<?php
class QuanHeModel extends AppModel{

    public $name = 'QuanHeModel';
    public $useTable = 'quanhe';
    public $primaryKey = 'id';
	
	public function layDanhSachTheoLoai($loai='',$itemCheck = '')
	{
		$result = $this->find('list', array(
			'conditions'=> array(
				'loai' 		=> $loai,
				'da_xoa' 	=> 0
			),
			'fields'	=> array(
				'QuanHeModel.loai_id',
				'QuanHeModel.ten_loai'
			),
			'order'		=> array('QuanHeModel.id')
		));
        $return = array();
        foreach ($result as $key => $value) {
            $return[$key]['value'] = $value;
            if (is_array($itemCheck) && in_array($key, $itemCheck)) {
                $return[$key]['checked'] = 'checked = "checked"';                
            } else if (!is_array($itemCheck) && $key == $itemCheck) {
                $return[$key]['checked'] = 'checked = "checked"';                
            } else {
                $return[$key]['checked'] = '';
            }
        }
        return $return;
	}	
} 